package me.dl.util

/**
  * Created by dl 
  */
object RichTuple {

  implicit class RichTuple2[T1, T2](val x: (T1, T2)) extends AnyVal {

    def append[T](elem: T): (T1, T2, T) = (x._1, x._2, elem)

    /**
      * append
      *
      * @param elem
      * @tparam T
      * @return
      */
    @inline def :+[T](elem: T): (T1, T2, T) = append(elem)

    /**
      * prepend
      *
      * @param elem
      * @tparam T
      */
    @inline def +:[T](elem: T): (T, T1, T2) = prepend(elem)

    def prepend[T](elem: T): (T, T1, T2) = (elem, x._1, x._2)

  }


  implicit class RichTuple3[T1, T2, T3](val x: (T1, T2, T3)) extends AnyVal {

    def append[T](elem: T): (T1, T2, T3, T) = (x._1, x._2, x._3, elem)

    /**
      * append
      *
      * @param elem
      * @tparam T
      * @return
      */
    @inline def :+[T](elem: T): (T1, T2, T3, T) = append(elem)

    /**
      * prepend
      *
      * @param elem
      * @tparam T
      */
    @inline def +:[T](elem: T): (T, T1, T2, T3) = prepend(elem)

    def prepend[T](elem: T): (T, T1, T2, T3) = (elem, x._1, x._2, x._3)
  }

  implicit class RichTuple4[T1, T2, T3, T4](val x: (T1, T2, T3, T4)) extends AnyVal {

    def append[T](elem: T): (T1, T2, T3, T4, T) = (x._1, x._2, x._3, x._4, elem)

    /**
      * append
      *
      * @param elem
      * @tparam T
      * @return
      */
    @inline def :+[T](elem: T): (T1, T2, T3, T4, T) = append(elem)


    def prepend[T](elem: T): (T, T1, T2, T3, T4) = (elem, x._1, x._2, x._3, x._4)

    /**
      * prepend
      *
      * @param elem
      * @tparam T
      */
    @inline def +:[T](elem: T): (T, T1, T2, T3, T4) = prepend(elem)
  }

}
